<?php
class Grocery_Advertisement_model extends grocery_CRUD_Model {

	/**
	 * @author Pwint Phyu Shwe
	 * Advertisement Model for tbl_advertisement and tbl_adv_category tables
	 * CRUD of advertisemet model.
	 * This model include pagination and related functions.
	 * Refer detail in each function's comment section below.
	 */
	// table name
	private $tbl_advertisement = 'advertisement';
	private $tbl_advcategory = 'adv_category';

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}
	// get number of users in database
	function count_all(){
		return $this->db->count_all($this->$tbl_advertisement);
	}
	// get persons with paging
	function get_paged_list($limit = 10, $offset = 0){
		$this->db->order_by('userID','asc');
		return $this->db->get($this->$tbl_advertisement, $limit, $offset);
	}
	// get advertisements by advertiserID
	function get_by_advertiserid($userID){
		$this->db->where('advertiserID', $userID);
		return $this->db->get($this->$tbl_advertisement);
	}
	// add new advertisement
	function save($advertisement){
		$this->db->insert($this->tbl_user, $advertisement);
		return $this->db->insert_id();
	}
	// update person by userID
	function update($userID, $person){
		
		$this->db->where('advid', $userID);
		$this->db->update($this->$tbl_advertisement, $user);
	}
	// delete person by advertiserID
	function delete($advertiserID){
		$this->db->where('userID', $userID);
		$this->db->delete($this->$tbl_advertisement);
	}
	
}
?>